<?php
header("Content-Type: text/html; charset=iso-8859-1");
require_once('include.php');
$_SESSION['navigation'] = 'infos';
$_SESSION['cat'] = 'infos';
$start = (!empty($_REQUEST['start'])) ? $_REQUEST['start'] : 1;
entete('VBCLL - Infos');
$proposer = (check_cookie()) ? "<span class = 'float_right'><button onclick = 'new_info()'>proposer une info</button></span>" : "";
echo "<div id = 'action'>\n";
echo "<h1>Les infos$proposer</h1>\n";
$id = (!empty($_REQUEST['id'])) ? $_REQUEST['id'] : "";
$comment = (!empty($_REQUEST['comment'])) ? $_REQUEST['comment'] : "";
$action = (!empty($_REQUEST['action'])) ? $_REQUEST['action'] : "";
if($id){
	echo "<div id = 'infos'></div>\n";
	echo "<div id = 'commentaires'></div>\n";
	echo "<script type = 'text/javascript'>liste_infos(0,1,$id)</script>\n";
	echo "<script type = 'text/javascript'>liste_commentaires_info($id)</script>\n";
	if($user_id = check_cookie()){
		echo "<a name = 'commentaires'></a><div id = 'ajout_commentaire'>\n";
		echo "	<form action = '#' method = 'post' onsubmit = 'return ajout_commentaire(this)' name = 'myform'>\n";
		$titre = "<input type = 'hidden' name = 'membre' value = '$user_id' />Ajouter un commentaire";
		$content = "<p class = 'center'><button type = 'button' name = 'citation' onclick = 'inserttag(\"_\",document.myform.contenu)'>_italique_</button>\n";
		$content .= "<button type = 'button' name = 'citation' onclick = 'inserttag(\"*\",document.myform.contenu)'>*gras*</button>\n";
		$content .= "<button type = 'button' name = 'citation' onclick = 'insertcode(\"\\n\\ncit%Auteur%. Texte%%\\n\\n\",document.myform.contenu)'>citation</button>\n";
		$content .= "<button type = 'button' name = 'citation' onclick = 'insertcode(\" &#39;&#39;Titre&#39;&#39;:http://adresse \",document.myform.contenu)'>lien</button></p>\n";
		$content .= "<p class = 'center'><input type = 'hidden' name = 'mytype' value = 'info' /><input type = 'hidden' name = 'id_info' value = '$id' />\n";
		$content .= "<textarea cols = '60' rows = '10' name = 'contenu'></textarea></p>\n";
		$content .= "<p class = 'center'><button type = 'submit'>ajouter</button></p>\n";
		echo box($titre,$content,690);
		echo "	</form>\n";
		echo "</div>\n";
	}
}
else{
	echo "<div id = 'infos_box'>\n";
	$q = "select * from infos where valide = 1 order by datetime desc";
	$r = ExecRequete($q);
	$max = mysql_num_rows($r);
	echo "<div id = 'next_info'>\n";
	if($start >= 40) echo "<a href = 'infos.php?start=".($start - 40)."'><img src = 'images/icon_precedent.png'  width = '53' height = '16'   alt = 'precedent' /></a>";
	echo "</div>\n";
	$i = 0;
	while($s = LigneSuivante($r)){
		if($i++ >= $start && $i < $start + 40){
			$info = new info($s->id);
			$auteur = new membre($s->membre_id);
			$texte_commentaire = ($info->nb_commentaires() < 2) ? $info->nb_commentaires()." commentaire" : $info->nb_commentaires()." commentaires";
			$titre = $s->titre;
			if(substr($s->corps,0,strlen('historique')) == 'historique'){
				$historique = new historique(substr($s->corps,strlen('historique')));
				$titre = "<span style = 'font: 14px Times, Serif'>[C'&eacute;tait il y a...]&nbsp;".$historique->titre."</span>";
			}
			echo "<div id = 'liste_info_$s->id' onclick = 'get_info($s->id)'>\n";
			echo "<p class = 'liste_titre_info'>\n";
			echo "<span class = 'liste_date_info'>".format_date($s->datetime)."</span>$titre</p>\n";
			echo "</div>\n";
		}
	}
	echo "<div id = 'previous'>\n";
	if($start + 40 < $max) echo "<a href = 'infos.php?start=".($start + 40)."'><span class = 'suivant'>suivant &darr;</span></a>";
	echo "</div>\n";
	echo "</div>\n";
}
echo "</div>\n";
pied();
?>
